<template>
	<view class="content" v-loading.fullscreen.lock="fullscreenLoading">
		<!-- <view class="">
			<button @click="getText">{{text}}</button>
		</view>
		<view class="" style="margin-top: 20rpx;">
			{{formData.conten}}
		</view> -->
		
		<el-tag type="danger">产品介绍</el-tag>
		<uni-forms ref="form" :value="formData" validateTrigger="bind">
			<uni-forms-item name="type_id">
				<usp-tinymce ref="matter" :isHtml="isHtml" v-model="formData.conten" :width="750" :height="460" />
			</uni-forms-item>
		</uni-forms>
		<el-button type="primary" @click="baocun">保 存</el-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fullscreenLoading: false,
				text: "切换纯文本",
				isHtml: true,
				formData: {
					"conten": "",
				}
			}
		},
		onShow() {
			this.onLoading()
		},
		methods: {
			onLoading() {
				this.fullscreenLoading = true
				uniCloud.callFunction({
					name: 'chanpin',
					data: {
						sign: 1
					} //标示：查询用，必填
				}).then((res) => {
					console.log('AAAAAA')
					console.log('res', res)
					if (res.result.data.length > 0) {
						this.tableData = res.result.data
						this.formData = this.tableData[0]
						this.fullscreenLoading = false
					} else {
						this.fullscreenLoading = false
						this.$message.error('数据初始化错误，刷新啊！')
					}
				})
			},
			baocun() {
				console.log(this.formData.conten)
				this.fullscreenLoading = true
				uniCloud.callFunction({
					name:'chanpin',
					data:Object.assign(this.formData,{sign:4})
				}).then((res)=>{
					this.fullscreenLoading = false
					this.onLoading()
				})
			},
			getText() {
				if (this.isHtml) {
					this.isHtml = false
					this.text = "切换带html"
				} else {
					this.isHtml = true
					this.text = "切换纯文本"
				}

			}
		}
	}
</script>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 30px;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
